<?php
declare(strict_types=1);

namespace app\common\subscribe;

use app\common\model\AdminUserModel;
use think\Event;
use think\facade\Log;

class AdminUserSubscribe
{

    /**
     * 管理员用户登录成功事件
     *
     * @param array $user
     *
     * @return void
     */
    public function onLoginSuccess(array $user = []): void
    {
        $data = [
            'id'          => $user['id'],
            'login_time'  => time(),
            'login_ip'    => request()->ip(),
            'login_count' => $user['login_count'] + 1
        ];
        AdminUserModel::update($data);
    }

    public function subscribe(Event $event): void
    {
        $event->listen('AdminUserLoginSuccess', [$this, 'onLoginSuccess']);
    }
}